package com.education.welco.controller;

import java.util.List;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.education.common.utils.ApiReturnObject;
import com.education.welco.pojo.TClassroom;
import com.education.welco.service.ITClassroomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 教室 信息操作处理
 *
 * @author d
 * @date 2020-05-11
 */
@RestController
@RequestMapping("/tClassroom")
public class TClassroomController  {

    @Autowired
    private ITClassroomService tClassroomService;


    /**
     * 查询教室列表
     */
    @GetMapping("/list")
    public ApiReturnObject list(TClassroom tClassroom,Integer pageNum,Integer pageSize) {
        if(pageNum != null && pageSize != null){
            PageHelper.startPage(pageNum,pageSize);
        }
        List<TClassroom> list = tClassroomService.selectTClassroomList(tClassroom);
        PageInfo<TClassroom> pageInfo = new PageInfo<>(list);
        return new ApiReturnObject("200","查询成功",pageInfo);
    }



    /**
     * 新增保存教室
     */
    @PostMapping("/add")
    public ApiReturnObject addSave(@RequestBody TClassroom tClassroom) {
        tClassroomService.insertTClassroom(tClassroom);
        return new ApiReturnObject("200","添加成功","");
    }


    /**
     * 修改保存教室
     */
    @PostMapping("/update")
    public ApiReturnObject editSave(@RequestBody TClassroom tClassroom) {
        tClassroomService.updateTClassroom(tClassroom);
        return new ApiReturnObject("200","修改成功","");
    }

    /**
     * 删除教室
     */
    @PostMapping("/del")
    public ApiReturnObject remove(String ids) {
        tClassroomService.deleteTClassroomByIds(ids);
        return new ApiReturnObject("200","删除成功","");
    }
}